Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[incubator-kie-drools-5792] [new-parser] improve drools-drl-parser-tests #5855

Conversation

tkobayas
Copy link
Contributor

@tkobayas tkobayas commented Apr 21, 2024

  • Old and new parser coverage using 2 surefire test executions
  • Fixed Descr common property issue to keep backward compatibility
  • A few test cases remaining without backward compatibility ("Backward Compatibility Notes" left) because the old parser seems to be wrong.
  • A few expr test cases remaining without backward compatibility ("Backward Compatibility Notes" left). Error code/message difference comes from antlr4 and 3 difference. Also the new parser ones are better.

Issue:

Before PR in drools-model-codegen

[ERROR] Tests run: 2434, Failures: 97, Errors: 0, Skipped: 9

After PR in drools-model-codegen

[ERROR] Tests run: 2434, Failures: 90, Errors: 0, Skipped: 9

…stsa to test with old and new parsers

- Old and new parser coverage using 2 surefire test executions
- Fixed Descr common property issues to keep backward compatibility
- A few test cases remaining without backward compatibility ("Backward Compatibility Notes" left) because the old parser seems to be wrong.
- A few expr test cases remaining without backward compatibility ("Backward Compatibility Notes" left). Error code/message don't seem to be important. Also the new parser ones are better.
@tkobayas tkobayas force-pushed the incubator-kie-drools-5854-improve-drools-drl-parser-tests branch from d3ec507 to e75d0d6 Compare April 21, 2024 06:31
Comment on lines +98 to +117
<execution>
<!-- override default-test for new parser -->
<id>default-test</id>
<configuration>
<systemPropertyVariables>
<drools.drl.antlr4.parser.enabled>true</drools.drl.antlr4.parser.enabled>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>old-parser-test</id>
<configuration>
<systemPropertyVariables>
<drools.drl.antlr4.parser.enabled>false</drools.drl.antlr4.parser.enabled>
</systemPropertyVariables>
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we can run old and new parser for the drools-drl-parser-tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand. Does this run the new tests (that we keep on adding to on this feature branch) against both the new and the old parser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yurloc Yes, in drools-drl-parser-tests, surefire runs twice with drools.drl.antlr4.parser.enabled = true and false. You would see:

[INFO] --- surefire:3.1.2:test (default-test) @ drools-drl-parser-tests ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.drools.drl.parser.antlr4.DRLExprParserTest
...
### parse : ANTLR4_PARSER_ENABLED = true
### parse : ANTLR4_PARSER_ENABLED = true
...
[INFO] 
[INFO] Results:
[INFO] 
[WARNING] Tests run: 351, Failures: 0, Errors: 0, Skipped: 17
[INFO] 
[INFO] 
[INFO] --- surefire:3.1.2:test (old-parser-test) @ drools-drl-parser-tests ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running org.drools.drl.parser.antlr4.DRLExprParserTest
...
### parse : ANTLR4_PARSER_ENABLED = false
### parse : ANTLR4_PARSER_ENABLED = false
...
[INFO] 
[INFO] Results:
[INFO] 
[WARNING] Tests run: 351, Failures: 0, Errors: 0, Skipped: 17

Comment on lines +393 to +395
// Backward Compatibility Notes:
// Antlr4 gives a different error code/message from antlr3 for this case.
// Backward compatibility doesn't seem to be required in this case.
Copy link
Contributor Author

@tkobayas tkobayas Apr 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave Backward Compatibility Notes when test results are different between old and new parser. We can categorize the cases into:

A) The difference comes from Antrl3 and 4, so we cannot change.
B) Old parser seems to be wrong and if we mimic the old behaviour, it would get unnecessarily complex. -> but, of course, we can discuss and look for compromise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please give us one or more examples of B)? In which cases the old parser is wrong? This would help us to focus this discussion and decide if it makes sense to pollute the new parser to accommodate the weird behaviors of the old one (I hope not).

Copy link
Contributor Author

@tkobayas tkobayas Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariofusco Sure, commented below. Probably it's easier to look in https://github.com/apache/incubator-kie-drools/pull/5855/files

Comment on lines +59 to +68
/**
* Determine if the current token is the end of a RHS DRL by lookahead.
* 1. 'end'
* 2. skip semi, WS, and comment
* 3. next token should be EOF or statement or attribute keyword
*
* TODO: This method is low-level and may be too complex in order to keep backward compatibility.
* This could be refactored by going back to a parser rather than the lexer island mode.
*/
boolean isRhsDrlEnd() {
Copy link
Contributor Author

@tkobayas tkobayas Apr 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRhsDrlEnd is required because we use lexer island mode and end has a tricky condition (to meet backward compatibility) for a semantic predicate. This method is low-level and too complex. I filed #5856 to investigate a better approach.

@tkobayas
Copy link
Contributor Author

@yurloc @gitgabrio @mariofusco Please review, thanks!

// Backward Compatibility Notes:
// Old expr parser (DRL6Expressions) allows this expression because it's too tolerant (fail at runtime anyway).
// Backward compatibility doesn't seem to be required in this case. (But we may align with the old tolerant behavior.)
if (DrlParser.ANTLR4_PARSER_ENABLED) {
Copy link
Contributor Author

@tkobayas tkobayas Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward Compatibility Notes : B) Old parser seems to be wrong

Old parser allows x.int.

Comment on lines +225 to +227
// Backward Compatibility Notes:
// The old DRL6Parser uses only the attribute value token for common properties (seem to be wrong), so startCharacter and column are different between old and new parser.
// Backward compatibility doesn't seem to be required in this case.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward Compatibility Notes : B) Old parser seems to be wrong

For TypeFieldDescr name : String ,
Old parser handles only String for common properties. So startCharacter is the position of S
New parser handles the whole expression (like other Descr), so startCharacter is the position of n

Comment on lines +246 to +248
// Backward Compatibility Notes:
// The old DRL6Parser uses only the attribute value token for common properties (seem to be wrong), so startCharacter and column are different between old and new parser.
// Backward compatibility doesn't seem to be required in this case. (If do it, the code would be unnecessarily complicated.)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward Compatibility Notes : B) Old parser seems to be wrong

For AttributeDescr salience 42 ,
Old parser handles only 42 for common properties. So startCharacter is the position of 4
New parser handles the whole expression (like other Descr), so startCharacter is the position of s

Comment on lines +349 to +351
// Backward Compatibility Notes:
// The old DRL6Parser doesn't populate common properties of FromDescr (seem to be wrong).
// Backward compatibility doesn't seem to be required in this case.
Copy link
Contributor Author

@tkobayas tkobayas Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward Compatibility Notes : B) Old parser seems to be wrong

Old parser doesn't populate FromDescr common properties. So all -1.

Comment on lines +387 to +389
// Backward Compatibility Notes:
// The old DRL6Parser doesn't populate common properties of EntryPointDescr (seem to be wrong).
// Backward compatibility doesn't seem to be required in this case.
Copy link
Contributor Author

@tkobayas tkobayas Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward Compatibility Notes : B) Old parser seems to be wrong

Old parser doesn't populate EntryPointDescr common properties. So all -1.

Comment on lines +408 to +410
// Backward Compatibility Notes:
// The old DRL6Parser doesn't populate common properties of WindowReferenceDescr (seem to be wrong).
// Backward compatibility doesn't seem to be required in this case.
Copy link
Contributor Author

@tkobayas tkobayas Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward Compatibility Notes : B) Old parser seems to be wrong

Old parser doesn't populate WindowReferenceDescr common properties. So all -1.

Copy link
Contributor

@yurloc yurloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +98 to +117
<execution>
<!-- override default-test for new parser -->
<id>default-test</id>
<configuration>
<systemPropertyVariables>
<drools.drl.antlr4.parser.enabled>true</drools.drl.antlr4.parser.enabled>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>old-parser-test</id>
<configuration>
<systemPropertyVariables>
<drools.drl.antlr4.parser.enabled>false</drools.drl.antlr4.parser.enabled>
</systemPropertyVariables>
</configuration>
<goals>
<goal>test</goal>
</goals>
</execution>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand. Does this run the new tests (that we keep on adding to on this feature branch) against both the new and the old parser?

final RuleDescr rule = pkg.getRules().get(0);
AndDescr and = rule.getLhs();
assertProperties(and, 21, 87, 3, 6, 3, 72);
assertProperties(and, 19, 90, 3, 4, 3, 74);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, I checked this one and the new numbers are correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, previously, it didn't include surrounding parentheses.

@tkobayas tkobayas merged commit 025ff72 into apache:dev-new-parser Apr 23, 2024
0 of 3 checks passed
tkobayas added a commit to tkobayas/drools that referenced this pull request Jun 11, 2024
…sts (apache#5855)

* [incubator-kie-drools-5854] [new-parser] improve drools-drl-parser-testsa to test with old and new parsers
- Old and new parser coverage using 2 surefire test executions
- Fixed Descr common property issues to keep backward compatibility
- A few test cases remaining without backward compatibility ("Backward Compatibility Notes" left) because the old parser seems to be wrong.
- A few expr test cases remaining without backward compatibility ("Backward Compatibility Notes" left). Error code/message don't seem to be important. Also the new parser ones are better.

* Update drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/LexerHelper.java

Co-authored-by: Jiří Locker <[email protected]>

* - removed unused import

---------

Co-authored-by: Jiří Locker <[email protected]>
tkobayas added a commit to tkobayas/drools that referenced this pull request Oct 2, 2024
…sts (apache#5855)

* [incubator-kie-drools-5854] [new-parser] improve drools-drl-parser-testsa to test with old and new parsers
- Old and new parser coverage using 2 surefire test executions
- Fixed Descr common property issues to keep backward compatibility
- A few test cases remaining without backward compatibility ("Backward Compatibility Notes" left) because the old parser seems to be wrong.
- A few expr test cases remaining without backward compatibility ("Backward Compatibility Notes" left). Error code/message don't seem to be important. Also the new parser ones are better.

* Update drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/LexerHelper.java

Co-authored-by: Jiří Locker <[email protected]>

* - removed unused import

---------

Co-authored-by: Jiří Locker <[email protected]>
tkobayas added a commit to tkobayas/drools that referenced this pull request Oct 11, 2024
…sts (apache#5855)

* [incubator-kie-drools-5854] [new-parser] improve drools-drl-parser-testsa to test with old and new parsers
- Old and new parser coverage using 2 surefire test executions
- Fixed Descr common property issues to keep backward compatibility
- A few test cases remaining without backward compatibility ("Backward Compatibility Notes" left) because the old parser seems to be wrong.
- A few expr test cases remaining without backward compatibility ("Backward Compatibility Notes" left). Error code/message don't seem to be important. Also the new parser ones are better.

* Update drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/LexerHelper.java

Co-authored-by: Jiří Locker <[email protected]>

* - removed unused import

---------

Co-authored-by: Jiří Locker <[email protected]>
tkobayas added a commit that referenced this pull request Oct 11, 2024
…sts (#5855)

* [incubator-kie-drools-5854] [new-parser] improve drools-drl-parser-testsa to test with old and new parsers
- Old and new parser coverage using 2 surefire test executions
- Fixed Descr common property issues to keep backward compatibility
- A few test cases remaining without backward compatibility ("Backward Compatibility Notes" left) because the old parser seems to be wrong.
- A few expr test cases remaining without backward compatibility ("Backward Compatibility Notes" left). Error code/message don't seem to be important. Also the new parser ones are better.

* Update drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/LexerHelper.java

Co-authored-by: Jiří Locker <[email protected]>

* - removed unused import

---------

Co-authored-by: Jiří Locker <[email protected]>
rgdoliveira pushed a commit to rgdoliveira/drools that referenced this pull request Oct 24, 2024
…sts (apache#5855)

* [incubator-kie-drools-5854] [new-parser] improve drools-drl-parser-testsa to test with old and new parsers
- Old and new parser coverage using 2 surefire test executions
- Fixed Descr common property issues to keep backward compatibility
- A few test cases remaining without backward compatibility ("Backward Compatibility Notes" left) because the old parser seems to be wrong.
- A few expr test cases remaining without backward compatibility ("Backward Compatibility Notes" left). Error code/message don't seem to be important. Also the new parser ones are better.

* Update drools-drl/drools-drl-parser/src/main/java/org/drools/drl/parser/antlr4/LexerHelper.java

Co-authored-by: Jiří Locker <[email protected]>

* - removed unused import

---------

Co-authored-by: Jiří Locker <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants